package io.springboot.jpa.examples.springbootjpaexamples.service.nosql;

import io.springboot.jpa.examples.springbootjpaexamples.model.nosql.BusinessMessage;
import io.springboot.jpa.examples.springbootjpaexamples.repository.nosql.BusinessMessageRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @author yzc
 * @description
 * @date 2018/9/23
 */
@Service
public class BusinessMessageService {

    @Autowired
    private BusinessMessageRepository businessMessageRepository;

    public BusinessMessage getOne(String serialnumber) {
        Optional<BusinessMessage> optionalBusinessMessage = businessMessageRepository.findById(serialnumber);
        if (optionalBusinessMessage.get() != null) {
            return optionalBusinessMessage.get();
        }
        return null;
    }

    public void save(BusinessMessage businessMessage) {
        businessMessageRepository.save(businessMessage);
    }
}
